home *** CD-ROM | disk | FTP | other *** search
/ CDUTIL 13 / CDUTIL #13 Julio 1995.iso / windows / acadcom / acrx / sample / ads_perr.cc next >
Encoding:
C/C++ Source or Header  |  1995-02-08  |  11.3 KB  |  314 lines

  1. /* Next available MSG number is  89 */
  2.  
  3. /*
  4.    ADS_PERR.CC
  5.  
  6.    Copyright (C) 1992, 1993, 1994 by Autodesk, Inc.
  7.  
  8.    Permission to use, copy, modify, and distribute this software in 
  9.    object code form for any purpose and without fee is hereby granted, 
  10.    provided that the above copyright notice appears in all copies and 
  11.    that both that copyright notice and the limited warranty and 
  12.    restricted rights notice below appear in all supporting 
  13.    documentation.
  14.  
  15.    AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.  
  16.    AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF 
  17.    MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE.  AUTODESK, INC.
  18.    DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE 
  19.    UNINTERRUPTED OR ERROR FREE.
  20.  
  21.    Use, duplication, or disclosure by the U.S. Government is subject to 
  22.    restrictions set forth in FAR 52.227-19 (Commercial Computer 
  23.    Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii) 
  24.    (Rights in Technical Data and Computer Software), as applicable.
  25.     
  26.    .
  27.  
  28.    ADS_PERR.C   -  ADS routine to print the error message
  29.                    associated with the value of "errno" upon failure
  30.                    of a call to AutoCAD.  This routine is meant to be
  31.                    invoked by other ADS programs, and contains a table
  32.                    of the current error messages as found in ol_errno.h.
  33.                    This routine is meant to parallel the Unix
  34.                    perror() function.
  35.  
  36.                    ads_perror() is a Lisp-callable or invokable function that
  37.                    takes an optional single argument and prints the message on
  38.                    the AutoCAD command line.  The syntax is:
  39.  
  40.                    (ads_perror "string")
  41.  
  42.                    The string is optional; if provided, it is printed on a
  43.                    separate line before the system error message.  To be of
  44.                    most use, the argument string should include the name of the
  45.                    program that incurred the error.  The error number is taken
  46.                    from the system variable "errno", which is set when most
  47.                    errors occur, but not cleared when non-erroneous calls are
  48.                    made.
  49.  */
  50.  
  51.  
  52. #include <stdlib.h>
  53. #include <iostream.h>
  54. #include <string.h>
  55. #include "rxdefs.h"
  56. #include "adslib.h"
  57. #include "ol_errno.h"
  58.  
  59.  
  60. #define ELEMENTS(array) (sizeof(array)/sizeof((array)[0]))
  61.  
  62.  
  63. /* ADS Function Table */
  64. typedef struct {
  65.     char    *name;
  66.     int     (*fptr)();
  67. } ftblent;
  68.  
  69.  
  70. extern int ads_perror();
  71.  
  72. int funcload   (void);
  73. int funcunload (void);
  74. int dofun      (void);
  75.  
  76.  
  77. /* The error message array */
  78. static struct {
  79.     int num;                          /* AutoCAD ERRNO code */
  80.     char *msg;                        /* Explanatory message */
  81. } errtbl[] = {
  82.     {  0, /*MSG88*/"Normal status; no error noted." },
  83.     {  1, /*MSG1*/"Invalid symbol table name." },
  84.     {  2, /*MSG2*/"Invalid name (entity or selection set) value." },
  85.     {  3, /*MSG3*/"Exceeded max number of selection sets." },
  86.     {  4, /*MSG4*/"Invalid selection set." },
  87.     {  5, /*MSG5*/"Improper use of Block Definition entity." },
  88.     {  6, /*MSG6*/"Improper use of Xref entity." },
  89.     {  7, /*MSG7*/"Entity selection failure by pick." },
  90.     {  8, /*MSG8*/"End of entity file." },
  91.     {  9, /*MSG9*/"End of Block Definition file." },
  92.     { 10, /*MSG10*/"Failure of eidlast." },
  93.     { 11, /*MSG11*/"Illegal entdel of Viewport." },
  94.     { 12, /*MSG12*/"Operation not allowed during PLINE." },
  95.     { 13, /*MSG13*/"Invalid handle." },
  96.     { 14, /*MSG14*/"Handles not enabled." },
  97.     { 15, /*MSG15*/"Invalid TRANS request." },
  98.     { 16, /*MSG16*/"Invalid space trans request." },
  99.     { 17, /*MSG17*/"Invalid use of deleted entity." },
  100.     { 18, /*MSG18*/"Invalid table name." },
  101.     { 19, /*MSG19*/"Invalid table function argument." },
  102.     { 20, /*MSG20*/"Attempt to set read-only variable." },
  103.     { 21, /*MSG21*/"Zero value invalid." },
  104.     { 22, /*MSG22*/"Value out of range." },
  105.     { 23, /*MSG23*/"Complex regen in progress." },
  106.     { 24, /*MSG24*/"Attempt to change entity type." },
  107.     { 25, /*MSG25*/"Bad layer name." },
  108.     { 26, /*MSG26*/"Bad linetype name." },
  109.     { 27, /*MSG27*/"Bad color name." },
  110.     { 28, /*MSG28*/"Bad text style name." },
  111.     { 29, /*MSG29*/"Bad shape name." },
  112.     { 30, /*MSG30*/"Bad field for entity type." },
  113.     { 31, /*MSG31*/"Attempted entmod of deleted entity." },
  114.     { 32, /*MSG32*/"Attempted entmod of SEQEND." },
  115.     { 33, /*MSG33*/"Attempt to change handle." },
  116.     { 34, /*MSG34*/"Illegal modification of viewport visibility." },
  117.     { 35, /*MSG35*/"Entity on locked layer." },
  118.     { 36, /*MSG36*/"Bad entity type." },
  119.     { 37, /*MSG37*/"Bad PLINE entity." },
  120.     { 38, /*MSG38*/"Incomplete complex entity in block." },
  121.     { 39, /*MSG39*/"Invalid block name field." },
  122.     { 40, /*MSG40*/"Duplicate block flag fields." },
  123.     { 41, /*MSG41*/"Duplicate block name fields." },
  124.     { 42, /*MSG42*/"Bad normal vector." },
  125.     { 43, /*MSG43*/"Missing block name." },
  126.     { 44, /*MSG44*/"Missing block flags." },
  127.     { 45, /*MSG45*/"Invalid anonymous block." },
  128.     { 46, /*MSG46*/"Invalid Block Definition entity." },
  129.     { 47, /*MSG47*/"Mandatory field missing." },
  130.     { 48, /*MSG48*/"Unrecognized extended data type." },
  131.     { 49, /*MSG49*/"Improper nesting of list in Xdata." },
  132.     { 50, /*MSG50*/"Improper location of APPID field." },
  133.     { 51, /*MSG51*/"Exceeded maximum Xdata size." },
  134.     { 52, /*MSG52*/"Entity selection failure by null response." },
  135.     { 53, /*MSG53*/"Duplicate application name in Xdata." },
  136.     { 54, /*MSG56*/"Attempt to make or modify Viewport entity." },
  137.     { 55, /*MSG57*/"Attempt to make an Xref or dependent symbol." },
  138.     { 56, /*MSG58*/"Bad ssget filter: unterminated clause." },
  139.     { 57, /*MSG59*/"Bad ssget filter: missing test operand." },
  140.     { 58, /*MSG60*/"Bad ssget filter: invalid test operation string." },
  141.     { 59, /*MSG61*/"Bad ssget filter: empty clause or improper nesting." },
  142.     { 60, /*MSG62*/"Bad ssget filter: begin/end clause mismatch." },
  143.     { 61, /*MSG63*/"Bad ssget filter: wrong number of XOR/NOT operands." },
  144.     { 62, /*MSG64*/"Bad ssget filter: maximum nesting level exceeded." },
  145.     { 63, /*MSG65*/"Bad ssget filter: invalid group code." },
  146.     { 64, /*MSG66*/"Bad ssget filter: invalid string test." },
  147.     { 65, /*MSG67*/"Bad ssget filter: invalid vector test." },
  148.     { 66, /*MSG68*/"Bad ssget filter: invalid real test." },
  149.     { 67, /*MSG69*/"Bad ssget filter: invalid integer test." },
  150.     { 68, /*MSG70*/"Digitizer isn't a tablet" },
  151.     { 69, /*MSG71*/"Tablet isn't calibrated." },
  152.     { 70, /*MSG72*/"Invalid arguments to (TABLET) function." },
  153.     { 71, /*MSG73*/"Not enough memory to allocate resbuf." },
  154.     { 72, /*MSG74*/"NULL Pointer was provided as an argument." },
  155.     { 73, /*MSG75*/"The specified file can't be opened." },
  156.     { 74, /*MSG76*/"The specified application is already loaded." },
  157.     { 75, /*MSG77*/"The maximum number of loaded ADS apps has been reached." },
  158.     { 76, /*MSG78*/"The specified application could not be executed." },
  159.     { 77, /*MSG79*/"The ADS app has an incompatible version number." },
  160.     { 78, /*MSG80*/"The ADS app is active or nested and can't be unloaded." },
  161.     { 79, /*MSG81*/"The ADS application refused to XUNLOAD." },
  162.     { 80, /*MSG82*/"The specified ADS application is not loaded." },
  163.     { 81, /*MSG83*/"Insuficient memory to load ADS application." },
  164.     { 82, /*MSG84*/"Invalid transformation matrix." },
  165.     { 83, /*MSG85*/"Invalid symbol name." },
  166.     { 84, /*MSG86*/"Invalid symbol value." },
  167.     { 85, /*MSG87*/"Operation not allowed while a dialogue box is active." },
  168. };
  169.  
  170. /* Table of ADS functions */
  171. ftblent exfun[] = {
  172.         {"ADS_PERROR", ads_perror},
  173. };
  174.  
  175.  
  176. extern "C" {                         
  177. AcRx::AppRetCode acrxEntryPoint(AcRx::AppMsgCode msg,void * pkt);
  178. }
  179.  
  180.  
  181. /******************************************************************************/
  182. /*.doc funcload(internal) */
  183. /*+
  184.     This function is called to define all function names in the ADS
  185.     function table.  Each named function will be callable from lisp or
  186.     invokable from another ADS application.
  187. -*/
  188. /******************************************************************************/
  189. int
  190. /*FCN*/funcload()
  191. {
  192.     int i;
  193.  
  194.     for (i = 0; i < ELEMENTS(exfun); i++) {
  195.         if (!ads_defun(exfun[i].name, i))
  196.             return RTERROR;
  197.         // When ads_regfunc works...
  198.         //
  199.         // ads_regfunc(ads_perror, 0) == RTNORM);
  200.     }
  201.     return RTNORM;
  202. }
  203.  
  204. /******************************************************************************/
  205. /*.doc funclunoad(internal) */
  206. /*+
  207.     This function is called to undefine all function names in the ADS
  208.     function table.  Each named function will be removed from the
  209.     AutoLISP hash table.
  210. -*/
  211. /******************************************************************************/
  212. int
  213. /*FCN*/funcunload()
  214. {
  215.     int i;
  216.  
  217.     /* Undefine each function we defined */
  218.  
  219.     for (i = 0; i < ELEMENTS(exfun); i++) {
  220.         ads_undef(exfun[i].name,i);
  221.     }
  222.  
  223.     return RTNORM;
  224. }
  225.  
  226. /******************************************************************************/
  227. /*.doc dofun(internal) */
  228. /*+
  229.     This function is called to invoke the function which has the
  230.     registerd function code that is obtained from  ads_getfuncode.  The
  231.     function will return RTERROR if the function code is invalid, or
  232.     RSERR if the invoked function fails to return RTNORM.  The value
  233.     RSRSLT will be returned if the function code is valid and the
  234.     invoked subroutine returns RTNORM.
  235. -*/
  236. /******************************************************************************/
  237. int
  238. /*FCN*/dofun()
  239. {
  240.     int    val;
  241.     int    rc;
  242.  
  243.     ads_retvoid();
  244.         
  245.     if ((val = ads_getfuncode()) < 0 || val > ELEMENTS(exfun))
  246.         return RTERROR;
  247.  
  248.     rc = (*exfun[val].fptr)();
  249.  
  250.     return ((rc == RTNORM) ? RSRSLT:RSERR);
  251. }
  252.  
  253.  
  254. AcRx::AppRetCode acrxEntryPoint(AcRx::AppMsgCode msg, void* ptr)
  255. {
  256.  
  257.     if (ptr != NULL) {
  258.         // We have been handed some kind of object
  259.         // but we aren't going to do anything with it.
  260.     }
  261.  
  262.     switch(msg) {
  263.     case AcRx::kInitAppMsg:
  264.         break;
  265.         case AcRx::kInvkSubrMsg:
  266.             dofun();
  267.             break;
  268.         case AcRx::kLoadADSMsg:
  269.             funcload();
  270.             break;
  271.         case AcRx::kUnloadADSMsg:
  272.             funcunload();
  273.             ads_printf(/*MSG2*/"Unloading.\n");
  274.             break;
  275.     case AcRx::kUnloadAppMsg:
  276.         default:
  277.         break;
  278.     }
  279.     return AcRx::kRetOK;
  280. }
  281.  
  282.  
  283. int
  284. ads_perror()
  285. {
  286.     int i;
  287.     struct resbuf *argl, errval;
  288.  
  289.     if (ads_getfuncode() != 0)        /* This is the ONLY function here */
  290.         return RSRSLT;
  291.  
  292.     if (ads_getvar(/*MSG0*/"ERRNO", &errval) == RTERROR)
  293.         return RSRSLT;
  294.  
  295.     argl = ads_getargs();
  296.     if (argl && argl->restype == RTSTR && strlen(argl->resval.rstring))
  297.         ads_printf("%s: ", argl->resval.rstring);
  298.  
  299.     for (i = 0; i < ELEMENTS(errtbl); i++)
  300.         if (errtbl[i].num == errval.resval.rint && errtbl[i].msg != NULL)
  301.             break;
  302.  
  303.     if (i < ELEMENTS(errtbl))
  304.         ads_printf("%s\n", errtbl[i].msg);
  305.     else
  306.         ads_printf("Unknown error code %d.\n", errval.resval.rint);
  307.  
  308.     ads_retvoid();
  309.  
  310.     return RSRSLT;
  311. }
  312.  
  313.  
  314.